package com.yanqu.road.logic.bussiness.player;

import com.yanqu.road.dao.impl.player.UserCombLeaderDaoImpl;
import com.yanqu.road.dao.impl.player.UserPatronsContractDaoImpl;
import com.yanqu.road.entity.player.*;
import com.yanqu.road.logic.bussiness.DaoHelper;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class UserPatronsBussiness {

	public static UserPatrons getUserPatrons(long userId,int patronsId) {
		return DaoHelper.getUserPatronsDaoImpl().getUserPatrons(userId,patronsId);
	}

	public static Map<Integer, UserPatrons> getUserPatronsMap(long userId) {
		return DaoHelper.getUserPatronsDaoImpl().getUserPatronsMap(userId);
	}

	public static Map<Long,Map<Integer, UserPatrons>> getSomeUserPatronsMap(List<Long> userIdList) {
		return DaoHelper.getUserPatronsDaoImpl().getSomeUserPatronsMap(userIdList);
	}

	public static Map<Integer, UserPatrons> getUserPatronsMap(long userId,List<Integer> patronsIdList) {
		return DaoHelper.getUserPatronsDaoImpl().getUserPatronsMap(userId,patronsIdList);
	}

	public static boolean addUserPatrons(UserPatrons userPatrons) {
		return DaoHelper.getUserPatronsDaoImpl().add(userPatrons);
	}

	public static boolean updateUserPatrons(UserPatrons userPatrons) {
		return DaoHelper.getUserPatronsDaoImpl().update(userPatrons);
	}

	public static List<UserPatronsSkill> getUserPatronsSkill(long userId,int patronsId) {
		return DaoHelper.getUserPatronsSkillDaoImpl().getUserPatronsSkill(userId,patronsId);
	}

	public static Map<Integer, List<UserPatronsSkill>> getUserPatronsSkillMap(long userId) {
		return DaoHelper.getUserPatronsSkillDaoImpl().getUserPatronsSkillMap(userId);
	}

	public static boolean addUserPatronsSkill(UserPatronsSkill userPatronsSkill) {
		return DaoHelper.getUserPatronsSkillDaoImpl().add(userPatronsSkill);
	}

	public static boolean updateUserPatronsSkill(UserPatronsSkill userPatronsSkill) {
		return DaoHelper.getUserPatronsSkillDaoImpl().update(userPatronsSkill);
	}

	public static Map<Integer, UserPatrons> getUserPatronsAndSkillMap(long userId) {
		Map<Integer, UserPatrons> userPatronsMap = getUserPatronsMap(userId);
		Map<Integer, List<UserPatronsSkill>> skillMap = getUserPatronsSkillMap(userId);
		Map<Integer, Map<Integer, UserPatronsContract>> userPatronsContractMap = new UserPatronsContractDaoImpl().getUserPatronsContract(userId);
		Map<Integer, UserCombLeaderData> leaderDataMap = new UserCombLeaderDaoImpl().getUserCombLeaderDataByPatronsKey(userId);
		//装备技能信息
		for (Map.Entry<Integer, List<UserPatronsSkill>> skillEntry : skillMap.entrySet()) {
			if (userPatronsMap.containsKey(skillEntry.getKey())) {
				userPatronsMap.get(skillEntry.getKey()).setSkillList(skillEntry.getValue());
			}
		}

		for (Map.Entry<Integer, Map<Integer, UserPatronsContract>> entry : userPatronsContractMap.entrySet()) {
			UserPatrons userPatrons = userPatronsMap.get(entry.getKey());
			if (userPatrons != null) {
				userPatrons.setPatronsContractMap(entry.getValue());
			}
		}

		for (UserCombLeaderData combLeaderData : leaderDataMap.values()) {
			UserPatrons userPatrons = userPatronsMap.get(combLeaderData.getLeaderId());
			if (userPatrons == null) {
				continue;
			}
			userPatrons.setCombLeaderSkillList(new ArrayList<>(combLeaderData.getSkillMap().values()));
			userPatrons.setLeaderPromotionId(combLeaderData.getPromoteId());
			userPatrons.setLeaderKeepSakePatronsId(combLeaderData.getKeepSakePatronsId());
		}

		return userPatronsMap;
	}

//	public static UserPatrons getUserPatronsAndSkill(long userId,int patronsId) {
//		UserPatrons userPatrons = getUserPatrons(userId,patronsId);
//		List<UserPatronsSkill> skillMap = getUserPatronsSkill(userId,patronsId);
//		userPatrons.setSkillList(skillMap);
//		return userPatrons;
//	}

	public static Map<Long, Map<Integer, UserPatronsSimple>> getUserPatronsSimpleMap() {
		return DaoHelper.getPatronsSimpleDaoImpl().getUserPatronsSimpleMap();
	}

	public static List<UserPatrons> getUserPatronsList(List<String> list) {
		return DaoHelper.getUserPatronsDaoImpl().getUserPatronsList(list);
	}


	/**
	 * 获取活跃 玩家的 门客总能力
	 * @param lastLoginTime
	 * @return
	 */
	public static Map<Long, Long> getActiveUserPatronsAbility(int lastLoginTime,int title){
		return DaoHelper.getUserPatronsDaoImpl().getActiveUserPatronsAbility(lastLoginTime, title);
	}

}
